﻿using UnityEngine;



//负责控制怪兽动画方面
public class MonsterAnimController : MonoBehaviour
{
    protected Animator animator;
    protected virtual void Start()
    {
        animator = GetComponent<Animator>();
    }


    public void Play(string animName)
    {
        animator.Play(animName);
    }


    public void Idle()
    {
        animator.SetBool(MonsterAnimName.Walk, false);
        animator.ResetTrigger(MonsterAnimName.Idle);
        animator.SetTrigger(MonsterAnimName.Idle);
    }


    public void Move(string moveName)
    {
        animator.ResetTrigger(moveName);
    }


    public void Walk()
    {
        animator.SetBool(MonsterAnimName.Walk, true);
    }


    public void Run()
    {
        animator.SetBool(MonsterAnimName.Run, true);
    }


    public void Jump()
    {
        animator.ResetTrigger(MonsterAnimName.Jump);
        animator.SetTrigger(MonsterAnimName.Jump);
    }


    public void Hit()
    {
        animator.ResetTrigger(MonsterAnimName.Hit);
        animator.SetTrigger(MonsterAnimName.Hit);
    }


    public void NormalAttack()
    {
        animator.ResetTrigger(MonsterAnimName.NormalAttack);
        animator.SetTrigger(MonsterAnimName.NormalAttack);
    }


    public bool IsAttackState()
    {
        AnimatorClipInfo[] currAnims = animator.GetCurrentAnimatorClipInfo(0);
        if (currAnims.Length == 0)
        {
            return false;
        }
        else
        {
            return currAnims[0].clip.name.Contains("Attack");
        }
    }


    public bool IsMovingState()
    {
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
        return stateInfo.IsName(MonsterAnimName.Walk) || stateInfo.IsName(MonsterAnimName.Run);
    }



    public bool IsCurrAnimName(string name)
    {
        return animator.GetCurrentAnimatorStateInfo(0).IsName(name);
    }


    public float GetCurrAnimNormalizedTime()
    {
        return animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
    }


    public bool HasParameterOfType(string name, AnimatorControllerParameterType type)
    {
        return animator.HasParameterOfType(name, type);
    }

}
